#include "StateManager.h"

CStateManager::CStateManager()
{
	pLogRelease << "StateManager created..." << endl;
}

CStateManager::~CStateManager()
{
}

void CStateManager::AddStateHandler(IStateHandler *nsh,u32 FirstState)
{
    shl.push_back(nsh);
    ChangeState(nsh,STATE_NOT_INIT);
    nsh->Update();
    ChangeState(nsh,STATE_START);
    nsh->Update();
    ChangeState(nsh,FirstState);
}

void CStateManager::Update()
{
    for (StateHandlerList::iterator it=shl.begin();it!=shl.end();it++)
    {
        (*it)->Update();
    }
}

void CStateManager::ChangeState(IStateHandler *sh,u32 newState)
{
    sh->ExitState();
    sh->SetState(newState);
    sh->EnterState();
}

void CStateManager::SetFinish(IStateHandler *sh)
{
	ChangeState(sh,STATE_END);
}
